package com.gxd.business.controller;

import com.gxd.business.domain.Customer;
import com.gxd.business.domain.qco.CustomerQco;
import com.gxd.business.service.CustomerService;
import com.gxd.common.core.controller.BaseController;
import com.gxd.common.core.domain.AjaxResult;
import com.gxd.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @author gxd
 * @since 2025/6/13
 */
@RestController
@RequestMapping("/customer")
@Api(tags = "资源客户管理")
public class CustomerController extends BaseController {

    @Autowired
    private CustomerService customerService;

    @ApiOperation("分页列表-资源客户列表")
    @PostMapping("/pageList")
    public TableDataInfo pageList(@ApiParam(value = "资源客户查询条件") @RequestBody CustomerQco customerQco) {
        List<Customer> customerList = customerService.pageList(customerQco);
        return getDataTable(customerList);
    }

    @ApiOperation("详情信息-根据Id获取资源客户详情信息")
    @ApiImplicitParam(name = "id", value = "资源客户Id", required = true, dataType = "String", paramType = "path")
    @GetMapping("/getById/{id}")
    public AjaxResult getById(@NotEmpty(message = "资源客户Id不能为空") @PathVariable String id) {
        return success(customerService.getDetailById(id));
    }

    @ApiOperation("添加或修改-资源客户")
    @PostMapping("/addOrEdit")
    public AjaxResult addOrEdit(@ApiParam(value = "资源客户实体", required = true) @Valid @RequestBody Customer customer) {
        return success(customerService.addOrEdit(customer));
    }

    @ApiOperation("删除-资源客户（支持批量）")
    @ApiImplicitParam(name = "ids", value = "资源客户Id（多个需要逗号分隔）", required = true, allowMultiple = true, dataType = "String", paramType = "path")
    @DeleteMapping("/removeById")
    public AjaxResult removeById(@RequestParam("ids") String ids) {
        return toAjax(customerService.deleteById(ids));
    }

    @ApiOperation("自动分配-资源客户")
    @GetMapping("/automaticAssign")
    public AjaxResult automaticAssign() {
        return toAjax(customerService.automaticAssign());
    }

    @ApiOperation("导入-资源客户")
    @PostMapping("/import")
    public AjaxResult importData(@ApiParam(value = "Excel文件", required = true) @RequestParam("file") MultipartFile file) {
        return toAjax(customerService.importData(file));
    }

    @ApiOperation("导出-资源客户")
    @GetMapping("/export")
    public void export(HttpServletResponse response, @ApiParam(value = "资源用户查询条件") CustomerQco customerQco) {
        customerService.export(response, customerQco);
    }
}
